package com.websuites.dao;

import java.util.HashMap;
import java.util.Map;

public abstract class DaoFactory {  
	
    public abstract Dao getDaoImpl(); 
    
    private static Map<String,DaoFactory> daoFactories = new HashMap<String, DaoFactory>();
    
    protected static DaoFactory getDaoFactory() { 
       DaoFactory daoFactory = null;
       if(daoType!=null){
	       if(daoFactories.containsKey(daoType)){
	 		   daoFactory = DaoFactory.daoFactories.get(daoType);
	 	   }else{
	 		   if(DAOType.WS_MYBATIS.equals(daoType)){
	 			   daoFactory = new MybatisDaoFactory(true);
	 			   daoFactories.put(DAOType.WS_MYBATIS, daoFactory);
	 		   }
	 		   else if(DAOType.MYBATIS.equals(daoType)){
	 			   daoFactory = new MybatisDaoFactory(false);
	 			   daoFactories.put(DAOType.MYBATIS, daoFactory);
	 		   }
	 	   }
       }
       return daoFactory;
    }
    
    public static DaoFactory getInstance() {
    	if(daoType==null){
    	  //try{}catch(Exception e){}
    		daoType = DAOType.WS_MYBATIS;
    		//daoType = DAOType.MYBATIS;
    	}
    	return getDaoFactory();
    }
    
    private static String daoType;

}  
